package com.wan.net.rpc.invoker.balancer;

import com.wan.net.rpc.service.RpcService;

import java.util.List;

/**
 * 根据索引，超出长度模除取余
 * @author wwh
 * @date 2022/6/22 16:19
 */
public class IndexBalancer implements Balancer<RpcService>{
    private final int index;

    public IndexBalancer(int index) {
        this.index = index;
    }

    @Override
    public RpcService choose(List<RpcService> list) {
        if(list == null || list.isEmpty()) return null;
        return list.get(index % list.size());
    }
}
